package ca.etsmtl.log430.lab2;

import java.util.Observable;

import ca.etsmtl.log430.common.Displays;
import ca.etsmtl.log430.common.Menus;
import ca.etsmtl.log430.common.Project;
import ca.etsmtl.log430.common.Resource;

/**
 * Upon notification, first lists the resources and asks the user to pick one by
 * specifying its ID. If the resource's ID is valid, then the projects assigned
 * to that resource are listed.
 * 
 * @author SP Therriault, B ing.
 * @version 1.0, 2013-Oct-16
 */

/*
 * Modification Log **********************************************************
 *
 * v1.0, SP Therriault, 16/10/2013 - Original version.
 *
 * ***************************************************************************
 */
public class ListProjectPreviouslyAssignedToResource extends Communication {

	public ListProjectPreviouslyAssignedToResource(Integer registrationNumber,String componentName) {
		super(registrationNumber, componentName);
	}
	
	/**
	 * The update() method is an abstract method that is called whenever the
	 * notifyObservers() method is called by the Observable class. First we
	 * check to see if the NotificationNumber is equal to this thread's
	 * RegistrationNumber. If it is, then we execute.
	 * 
	 * @see ca.etsmtl.log430.lab2.Communication#update(java.util.Observable,
	 *      java.lang.Object)
	 */
	public void update(Observable thing, Object notificationNumber) {
		Menus menu = new Menus();
		Displays display = new Displays();
		Resource myResource = new Resource();
		
		//Compares the thread number if it's the same.
		if (registrationNumber.compareTo((Integer)notificationNumber) == 0){
			
			addToReceiverList("ListResourcesComponent");
			
			// Display the projects and prompt the user to pick one
			signalReceivers("ListResourcesComponent");
			
			myResource = menu.pickResource(CommonData.theListOfResources.getListOfResources());
			
			if (myResource != null){
				
				display.displayProjectsPreviouslyAssignedToResource(myResource, CommonData.theListOfProjects.getListOfProjects());
				
			}else{
				System.out.println("\n\n *** Resource not found ***");
			}
			
		}
		removeFromReceiverList("ListResourcesCompoment");
	}

}
